<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>
<%@ page import="com.hzqy.web.vo.PmsUserVo"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>节目增加</title>
    <link rel="stylesheet" type="text/css"	href="static/js/themes/defalut.css">
    <link rel="stylesheet" type="text/css"	href="static/js/themes/public.css">
    <link rel="stylesheet" type="text/css"	href="static/js/themes/ddspstyle.css">
    <link rel="stylesheet" type="text/css"	href="static/js/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css"	href="static/js/themes/icon.css">
    <link rel="stylesheet" type="text/css"	href="static/js/WdatePicker/skin/WdatePicker.css">
    <script type="text/javascript" src="static/js/jquery.min.js"></script>
    <script type="text/javascript" src="static/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="static/js/jquery.md5.js"></script>
    <script type="text/javascript"	src="static/js/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="static/js/jquery.validate.js"></script>
    <script type="text/javascript" src="static/js/index.js"></script>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <%
        String ppd_set_times = request.getParameter("pwd_set_times");
    %>
    <script type="text/javascript">
        var orderId2="";
        var pwd_set_times="<%=ppd_set_times%>";
        function checkMobile(phone){
            if(!(/^1[3|4|5|8|7][0-9]\d{4,8}$/.test(phone))||phone.length!=11){
                return false;
            } else{
                return true;
            }
        }
        function sendYzm() {
            var phone=document.getElementById("f_pu_phone").value;
            $("#f_pu_name_tip").html("");
            $("#f_pu_pwd_tip").html("");
            $("#f_pu_phone_tip").html("");
            $("#f_pu_new_phone_tip").html("");
            $("#dx_yzm_tip").html("");
            if ($.trim($("#f_pu_name").val()).length == 0) {
                $("#f_pu_name_tip").html("请输入用户名").show();
                $("#f_pu_name").focus();
                return false;
            }else if ($.trim($("#f_pu_pwd").val()).length < 6 || $.trim($("#f_pu_pwd").val()).length >16) {
                $("#f_pu_pwd_tip").html("密码不正确").show();
                $("#f_pu_pwd").focus();
                return false;
            }else if (document.getElementById("f_pu_phone").length < 11) {
                $("#f_pu_phone_tip").html("请输入正确的手机号").show();
                $("#f_pu_phone").focus();
                return false;
            }else if (!checkMobile(document.getElementById("f_pu_phone").value)) {
                $("#f_pu_phone_tip").html("请输入正确的手机号").show();
                $("#f_pu_phone").focus();
                return false;
            }
            var date = new Date();
            var year = date.getFullYear();
            var month=(date.getMonth()+1)>9?(date.getMonth()+1):'0'+(date.getMonth()+1);
            var day=date.getDate()>9?(date.getDate()):'0'+(date.getDate());
            var riqi=year+'-'+month+'-'+day;
            var startTime=riqi+" 00:00:00";
            var endTime=riqi+" 23:59:59";
            $.ajax({
                url: "wchat/MessageCount.do",
                data: {
                    startTime:startTime,
                    endTime:endTime,
                    phones:phone,
                    smsType:4
                },
                dataType: 'json',
                type: 'post',
                success: function (count) {
                    if (parseInt(''+count)<=parseInt(pwd_set_times)) {
                        $.ajax({
                            url: "pms/findUser.do",
                            data: {
                                f_pu_name: $('#f_pu_name').val(),
                                f_pu_pwd: $.md5($("#f_pu_pwd").val()),
                                f_pu_phone: phone
                            },
                            dataType: 'json',
                            type: 'post',
                            success: function (json) {
                                if (json.status==="success") {
                                    //发送验证码
                                    $.ajax({
                                        url: "wchat/sendLoginMessage.do",
                                        data: {
                                            name: $('#f_pu_name').val(),
                                            phones: phone,
                                            smsType: 4,
                                            login_type:"1"
                                        },
                                        dataType: 'json',
                                        type: 'post',
                                        success: function (json) {
                                            if (json.state) {
                                                $("#dx_yzm_tip").html(json.state).show();
                                            } else if (json.resCode == "P00000") {
                                                orderId2 = json.liuliuOrderId;
                                                console.log("验证码发送成功!");
                                                $("#dx_yzm_tip").html("验证码已发送!").show();
                                            } else {
                                                $("#dx_yzm_tip").html("验证码发送失败!").show();
                                            }
                                        }
                                    });
                                }else {
                                    $("#dx_yzm_tip").html(""+json.msg).show();
                                }
                            }
                        });
                    }else{
                        //修改用户状态
                        $.ajax({
                            url : "pms/updateUserStatus.do",
                            data : {
                                f_pu_name: $('#f_pu_name').val(),
                                f_pu_phone : phone,
                                f_pu_status:2
                            },
                            dataType : 'json',
                            type : 'post',
                            success : function(json) {
                                console.log(json.success);
                            }
                        });
                        $("#dx_yzm_tip").html("已超出重置上限，冻结账号!").show();
                    }
                },
                error:function(){

                }
            });
        }

        function _submitFm() {
            $("#f_pu_name_tip").html("");
            $("#f_pu_pwd_tip").html("");
            $("#f_pu_phone_tip").html("");
            $("#f_pu_new_phone_tip").html("");
            $("#dx_yzm_tip").html("");

            if ($.trim($("#f_pu_name").val()).length == 0) {
                $("#f_pu_name_tip").html("请输入用户名").show();
                $("#f_pu_name").focus();
                return false;
            }else if ($.trim($("#f_pu_pwd").val()).length < 6 || $.trim($("#f_pu_pwd").val()).length >16) {
                $("#f_pu_pwd_tip").html("密码不正确").show();
                $("#f_pu_pwd").focus();
                return false;
            }else if (document.getElementById("f_pu_phone").length < 11) {
                $("#f_pu_phone_tip").html("请输入正确的手机号").show();
                $("#f_pu_phone").focus();
                return false;
            }else if (!checkMobile(document.getElementById("f_pu_phone").value)) {
                $("#f_pu_phone_tip").html("请输入正确的手机号").show();
                $("#f_pu_phone").focus();
                return false;
            }else if (document.getElementById("f_pu_new_phone").length < 11) {
                $("#f_pu_new_phone_tip").html("请输入正确的手机号").show();
                $("#f_pu_new_phone_tip").focus();
                return false;
            }else if (!checkMobile(document.getElementById("f_pu_new_phone").value)) {
                $("#f_pu_new_phone_tip").html("请输入正确的手机号").show();
                $("#f_pu_new_phone").focus();
                return false;
            }else if ((document.getElementById("dx_yzm").value==="")) {
                $("#dx_yzm_tip").html("请获取验证码").show();
                $("#dx_yzm").focus();
                return false;
            }
            var yzm = document.getElementById("dx_yzm").value;
            //查询订单号
            $.ajax({
                url: "wchat/smsInfo.do",
                data: {
                    phone: document.getElementById("f_pu_phone").value,
                    smsType: 4,
                    login_type:"1"
                },
                dataType: 'json',
                type: 'post',
                success: function (json) {
                    if(json){
                        $.ajax({
                            url: "wchatHotel/wx_phone_yzm.do",
                            data: {
                                phone: document.getElementById("f_pu_phone").value,
                                yzm: yzm,
                                orderId:json.orderId,
                                smsType:4,
                                login_type:"1"
                            },
                            dataType: 'json',
                            type: 'post',
                            success: function (json) {
                                if(json.code=="1000"){
                                    //校验成功 修改手机号
                                    $.ajax({
                                        url : "pms/updateUserPhone.do",
                                        data : {
                                            f_pu_name: $('#f_pu_name').val(),
                                            f_pu_pwd: $.md5($("#f_pu_pwd").val()),
                                            f_pu_phone:$('#f_pu_phone').val(),
                                            newPhone:$('#f_pu_new_phone').val()
                                        },
                                        dataType : 'json',
                                        type : 'post',
                                        success : function(json) {
                                            if(json.status==="error"){
                                                window.alert(json.msg+" 修改失败");
                                            }else{
                                                parent.$('#dlg').dialog('close');
                                                setTimeout(function () {
                                                    window.alert(json.msg);
                                                },800);

                                            }
                                        }
                                    });
                                }else{
                                    $("#dx_yzm_tip").html("验证码错误").show();
                                }
                            }
                        });
                    }else{
                        $("#dx_yzm_tip").html("请获取验证码").show();
                    }
                },
                error:function(){
                    $("#dx_yzm_tip").html("请获取验证码").show();
                }
            });
        }
    </script>
    <style type="text/css">
    </style>
</head>

<body class="overfwidth">
<div class="barnavtop"></div>
<div id="workspace">
    <!--主体 开始-->
    <div id="container-1">
        <div class="editspace">
            <form id="contentForm" class="cmxform" enctype="multipart/form-data" name="formName">
                <legend style="text-align: center; margin: 0 auto;">修改手机号</legend>
                <fieldset>
                    <div class="fitem">
                        <table width="100%" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td width="20%" align="right">
                                    用户名:
                                </td>
                                <td width="30%">
                                    <input id="f_pu_name" name="f_pu_name" style="width: 150px;" value="" class="yl_inp yw_name" />
                                    <span id="f_pu_name_tip" class="tip red"></span>
                                </td>
                            </tr>
                        </table>
                    </div>
                </fieldset>
                <fieldset>
                    <div class="fitem">
                        <table width="100%" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td width="20%" align="right">
                                    密码:
                                </td>
                                <td width="30%">
                                    <input id="f_pu_pwd" name="f_pu_pwd" style="width: 150px;" value="" class="yl_inp yw_pwd" />
                                    <span id="f_pu_pwd_tip" class="tip red"></span>
                                </td>
                            </tr>
                        </table>
                    </div>
                </fieldset>

                <fieldset>
                    <div class="fitem">
                        <table width="100%" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td width="20%" align="right">
                                    原手机号:
                                </td>
                                <td width="30%">
                                    <input id="f_pu_phone" name="f_pu_phone" style="width: 150px;" value="" class="yl_inp yw_name" />
                                    <span id="f_pu_phone_tip" class="tip red"></span>
                                </td>
                            </tr>
                        </table>
                    </div>
                </fieldset>
                <fieldset>
                    <div class="fitem">
                        <table width="100%" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td width="20%" align="right">
                                    新手机号:
                                </td>
                                <td width="30%">
                                    <input id="f_pu_new_phone" name="f_pu_new_phone" style="width: 150px;" value="" class="yl_inp yw_name" />
                                    <span id="f_pu_new_phone_tip" class="tip red"></span>
                                </td>
                            </tr>
                        </table>
                    </div>
                </fieldset>
                <fieldset>
                    <div class="fitem">
                        <table width="100%" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td width="22%" align="right">
                                    验证码:
                                </td>
                                <td width="8%">
                                    <input id="dx_yzm" name="dx_yzm" style="width: 150px;" value="" class="yl_inp yw_name" />
                                </td>
                                <td width="20%">
                                    <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
                                       href="javascript:void(0);" onclick="sendYzm()">验证码</a>
                                    <span id="dx_yzm_tip" class="tip red"></span>
                                </td>
                            </tr>
                        </table>
                    </div>
                </fieldset>

                <div class="toolbar" style="text-align: center;">
                    <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
                       href="javascript:void(0);" onclick="_submitFm()">保存</a> <a
                        href="javascript:void(0);" data-options="iconCls:'icon-cancel'"
                        class="easyui-linkbutton"
                        onclick="javascript:parent.$('#dlg').dialog('close')">取消</a>
                </div>
            </form>
        </div>
    </div>
    <!--主体 结束-->
</div>

</body>
</html>

